<?php

$__FILEPATH__ = dirname(__FILE__)."/";
require_once($__FILEPATH__."./func_common.php");
require_once($__FILEPATH__."./class_def.php");
require_once($__FILEPATH__."./conf/info.php");

session_start();

if (!isset($_SESSION["user"]))
{
	header("HTTP/1.0 403 Forbidden");
	header("Content-Type: text/html; charset=UTF-8");
	echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n";
	echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"zh\" xml:lang=\"zh\">\r\n";
	echo "<head>\r\n";
	echo "<title>HTTP 403 Forbidden</title>\r\n";
	echo "</head>\r\n<body>";
	echo "<p style=\"height: 20%;\">&nbsp;</p>";
	echo "<h1 style=\"text-align: center\">HTTP 403 Forbidden</h1>";
	echo "<hr />";
	echo "<h1 style=\"text-align: center\">未登录者不得察看用户个人信息</h1>";
	echo "</body>\r\n</html>\r\n";
	exit(0);
}

if (!isset($_GET["user"]) || $_GET["user"] == "")
{
	header("HTTP/1.1 301 Moved Permanently");
	header("Content-Type: text/plain; charset=UTF-8");
	header("Location: /");
	exit(0);
}

header("Content-Type: text/html; charset=UTF-8");

$mysqli = GetMysqliInstance();
$UserItem = new UserListItem();

$stmt = $mysqli->prepare("select username, password, nickname, sex, school, email, imagesrc, intra, ip, rgtime, permission from userlist where username=?");

$ret = true;

do
{
	if (!$stmt)
	{
		$ret = false;
		break;
	}

	$stmt->bind_param("s", $_GET["user"]);
	if (!$stmt->execute())
	{
		$ret = false;
		break;
	}

	$stmt->bind_result($r_username, $r_password, $r_nickname, $r_sex, $r_school, $r_email, $r_imagesrc, $r_intra, $r_ip, $r_rgtime, $r_permission);
	if ( !$stmt->fetch() )
	{
		$ret = false;
		break;
	}

	$UserItem->username 	= $r_username;
	$UserItem->password 	= $r_password;
	$UserItem->nickname 	= $r_nickname;
	$UserItem->sex 			= $r_sex;
	$UserItem->school		= $r_school;
	$UserItem->email 		= $r_email;
	$UserItem->imagesrc 	= $r_imagesrc;
	$UserItem->intra 		= $r_intra;
	$UserItem->ip 			= $r_ip;
	$UserItem->rgtime 		= $r_rgtime;
	$UserItem->permission 	= $r_permission;

}while(false);

$stmt->close();
$mysqli->close();

?>